package com.xpgk.mvc.statistic.monthSales;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.statistic.daySales.DaySalesStatisticSQL;
import com.xpgk.mvc.user.User;

public class MonthSalesStatisticController extends BaseController{
	
	
	private  MonthSalesStatisticService  monthSalesStatisticService;
	
	public void index() {
		String sql = getSqlMy(DaySalesStatisticSQL.sqlId_product);
		setAttr("products", Db.find(sql, Code.lc_ids, Code.proYt_ids));
		setAttr("curOrgan", Organization.dao.findById(getCUserOrganIds()));
		render("monthSalesStatistic.html");
	}
	
	public void view(){
		String date = getPara("curDate", "-1");
		String organIds = getPara("organIds", "-1");
		List<Record> result=monthSalesStatisticService.getView(date,organIds);
		renderJson(result);
	}
	
	public void excel(){
		String date = getPara("curDate", "-1");
		String organIds = getPara("organIds", "-1");
		List<Record> result=monthSalesStatisticService.getView(date,organIds);
		
		//搜索条件
		Organization  organ=Organization.dao.findById(getPara("organIds", "-1"));
		String  search="日期："+getPara("curDate", "-1")+",门店："+organ.getStr(Organization.column_name)+",导出人员："+getCUser().getStr(User.column_name);
		render(new MonthSalesStatisticXLS(result, search,"月度每日销售汇总查询表"));
	}
	
}
